package md.mru.frontend.controllers;

import md.mru.core.domains.type.RolesType;
import md.mru.core.domains.type.SystemTagType;
import md.mru.core.dtos.*;
import md.mru.core.service.AdministrationService;
import md.mru.core.service.FolderService;
import md.mru.core.service.OrderService;
import org.apache.log4j.Logger;
import org.springframework.security.crypto.bcrypt.BCrypt;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author sergiu.marin
 * @since 31/05/2014.
 */
@ManagedBean
@ViewScoped
public class GroupAdministrationBean extends BackingBean implements Serializable {

    private static final long serialVersionUID = 8875609803999690611L;

    Logger logger = Logger.getLogger(GroupAdministrationBean.class);

    @ManagedProperty(value = "#{administrationService}")
    private AdministrationService administrationService;

    private List<UserGroupDto> groups;
    private UserGroupDto selectedUserGroup;
    private RolesType[] roles = RolesType.values();

    public void initializeGroupssContent() {
        groups = administrationService.getGroups();
    }

    /*public void addNewGroup() {
        this.selectedUserGroup = new UserGroupDto();
    }*/

    public void saveGroup() {
        long groupId = administrationService.saveGroup(selectedUserGroup);
        if (selectedUserGroup.getId() == 0) {
            selectedUserGroup.setId(groupId);
            groups.add(selectedUserGroup);
        }
    }

    public void deleteUserGroup(UserGroupDto userGroup) {
        administrationService.deleteUserGroup(userGroup.getId());
        this.groups.remove(userGroup);
    }

    public List<UserGroupDto> getGroups() {
        return groups;
    }

    public void resetCreateUserGroupDialog() {
        this.selectedUserGroup = new UserGroupDto();
    }

    public UserGroupDto getSelectedUserGroup() {
        return selectedUserGroup;
    }

    public void setSelectedUserGroup(UserGroupDto selectedUserGroup) {
        this.selectedUserGroup = selectedUserGroup;
    }

    public void setAdministrationService(AdministrationService administrationService) {
        this.administrationService = administrationService;
    }

    public RolesType[] getRoles() {
            return roles;
        }
}
